package com.tanhua.app.controller;


import com.tanhua.app.Service.SmallVideoService;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.VideoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.ws.rs.GET;
import java.io.File;
import java.io.IOException;

@RestController
@RequestMapping("/smallVideos")
public class SmallVideoController {

    @Autowired
    SmallVideoService smallVideoService;

    /**
     * 发布视频
     *  接口路径：POST
     *  请求参数：
     *      videoThumbnail：封面图
     *      videoFile：视频文件
     */

    @PostMapping
    public ResponseEntity smallVideos(MultipartFile videoThumbnail, MultipartFile videoFile) throws IOException {
        smallVideoService.saveVideos(videoThumbnail,videoFile);
        return ResponseEntity.ok(null);
    }

//    接口名称：小视频列表
//    接口路径：GET/smallVideos
    @GetMapping
    public ResponseEntity smallVideosList(@RequestParam(defaultValue = "1") Integer page,
                                          @RequestParam(defaultValue = "10") Integer pagesize){

        PageResult<VideoVo> vo = smallVideoService.saveVideosList(page,pagesize);
        return ResponseEntity.ok(vo);
    }


}
